Level2 = Class.extend({
	init: function(context, images) {
		this.context = context;
		this.image = images;
		this.initEnemyL2 = 3000;
		this.enemyAlive = 0;
	},
	
	initEnemy: function() {
		var self = this;
		
		this.generateRandomEnemies(self);
        this.chooseEnemyInterval = setInterval(function() { 
        	self.generateRandomEnemies(self);
        }, self.initEnemyL2);
	},
	
	generateRandomEnemies: function(self) {
		
	    var randomNumber = Math.floor(Math.random()*4);
	    this.Shoot = 0;
	    	    	
	    switch (randomNumber) {
		case 0:
			self.enemy21 = new Enemy21(self.context, self.image[0]);		
			self.activEnemyPosition = self.enemy21.initEnemy(self.Shoot);
			self.enemy21.shooterEnemy(true);
			self.enemyAlive = 21;
			break;
		case 1:
			self.enemy22 = new Enemy22(self.context, self.image[1]);
			self.activEnemyPosition = self.enemy22.initEnemy(self.Shoot);
			self.enemy22.shooterEnemy(true);
			self.enemyAlive = 22;
			break;
		case 2:
			self.enemy23 = new Enemy23(self.context, self.image[4]);
			self.activEnemyPosition = self.enemy23.initEnemy(self.Shoot);
			self.enemy23.shooterEnemy(true);
			self.enemyAlive = 23;
			break;
		case 3:
			self.enemy24 = new Enemy24(self.context, self.image[5]);
			self.activEnemyPosition = self.enemy24.initEnemy(self.Shoot);
			self.enemy24.shooterEnemy(true);
			self.enemyAlive = 24;
			break;
		default:
			break;
		}
	  
	},
	
	checkedPosition: function(mouseCoordinate) {
		var self = this;
		this.mouseCoordinateX = mouseCoordinate[0];
		this.mouseCoordinateY = mouseCoordinate[1];
       		
        if(this.mouseCoordinateX > self.activEnemyPosition[0] && this.mouseCoordinateX < self.activEnemyPosition[2] &&
        	this.mouseCoordinateY > self.activEnemyPosition[1] && this.mouseCoordinateY < self.activEnemyPosition[3] ){
        
        	this.playerMoney +=100;
            this.playerPoint +=100;
            
            this.Shoot++;
            
            switch (self.enemyAlive) {
			case 21:
				self.enemy21.dyingEnemy(self.Shoot);
                self.enemy21.shooterEnemy(false);
				break;
			case 22:
				self.enemy22.dyingEnemy(self.Shoot);
                self.enemy22.shooterEnemy(false);
				break;
			case 23:
				self.enemy23.dyingEnemy(self.Shoot);
                self.enemy23.shooterEnemy(false);
				break;	
			case 24:
				self.enemy24.dyingEnemy(self.Shoot);
                self.enemy24.shooterEnemy(false);
				break;
			default:
				break;
			};
			
			if(self.Shoot === 1) {
				setTimeout(function() {
					clearInterval(self.chooseEnemyInterval);   
					self.initEnemy();
				}, 680)
			}
			
          };
  
	}
})